﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class AdminX_Tour_TourBookingAdd : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MessAlert1.HideMessage();
        if (!IsPostBack)
        {
            SetLabelLanguage();
            ValidateControl();
            BindDataWhenEdit();
        }
    }
    private void SetLabelLanguage()
    {
        int nDefaultLanguage = Support.GetDefaultLanguage();
        lblAddress.Text = MultipleLanguage.LBL_ADDRESS[nDefaultLanguage - 1];

        lblAdult.Text = MultipleLanguage.LBLADULT[nDefaultLanguage - 1];//
        lblChild.Text = MultipleLanguage.LBLCHILD[nDefaultLanguage - 1];

        lblContactEmail.Text = MultipleLanguage.EMAIL[nDefaultLanguage - 1];
        lblContactFullname.Text = MultipleLanguage.FULLNAME[nDefaultLanguage - 1];
        lblContactPhone.Text = MultipleLanguage.TELEPHONE[nDefaultLanguage - 1];

        lblKid.Text = MultipleLanguage.LBLKID[nDefaultLanguage - 1];
        lblTotalPerson.Text = MultipleLanguage.LBLTOTALPERSON[nDefaultLanguage - 1];
        
        lblTour.Text = MultipleLanguage.LBL_TOUR[nDefaultLanguage - 1];

        btnBack.Text = MultipleLanguage.BTN_BACK[nDefaultLanguage - 1];
    }
    private void ValidateControl()
    {
    }
    #region Relative Functions
    private void BindDataWhenEdit()
    {
        string sAction = ConvertData.ConvertToString(Request.QueryString[Config.ACTION]);
        try
        {
            if (sAction == Config.ACTION_EDIT)
            {
                int nID = ConvertData.ConvertToInt(Request.QueryString[Config.ACTION_ID]);
                if (nID > 0)
                    GetData(nID);
            }
        }
        catch
        {
            string sLink = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOURBOOKING;
            Response.Redirect(sLink);
        }
    }
    private void GetData(int nID)
    {
        TourBooking objTourBooking = new TourBooking();
        objTourBooking.LoadById(nID);

        Tours objTour = new Tours();
        objTour.LoadById(objTourBooking.Data.TourID);
        int nDefaultLanguage = Support.GetDefaultLanguage();
        switch (nDefaultLanguage)
        {
            case 1:
                lblValTour.Text = ConvertData.ConvertToString(objTour.Data.Title1);
                break;
            case 2:
                lblValTour.Text = ConvertData.ConvertToString(objTour.Data.Title2);
                break;
            case 3:
                lblValTour.Text = ConvertData.ConvertToString(objTour.Data.Title3);
                break;

        }
        lblValAdult.Text = ConvertData.ConvertToString(objTourBooking.Data.Adult);
        lblValChild.Text = ConvertData.ConvertToString(objTourBooking.Data.Child);//
        lblValKid.Text = ConvertData.ConvertToString(objTourBooking.Data.Kid);//
        //-
        int nStatus = 0;
        nStatus = ConvertData.ConvertToInt(objTourBooking.Data.Status);
        lblValTotalPerson.Text = ConvertData.ConvertToString(objTourBooking.Data.TotalPerson);//
        lblValContactAddress.Text = ConvertData.ConvertToString(objTourBooking.Data.ContactAddress);//
        lblValContactEmail.Text = ConvertData.ConvertToString(objTourBooking.Data.ContactEmail);//
        lblValContactFullname.Text = ConvertData.ConvertToString(objTourBooking.Data.ContactFullname); //
        txtContactPhone.Text = ConvertData.ConvertToString(objTourBooking.Data.ContactPhone);//
        int Result = objTourBooking.UpdateStatus(nID, EnumeType.ACTIVE);
    }
    #endregion

    #region Click Events
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect(Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOURBOOKING);
    }
    #endregion
}